//
//  vechileSearchViewController.m
//  WHB_cargo
//
//  Created by 徐国庆 on 15/12/14.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "vechileSearchViewController.h"
#import "logisticsVechileViewController.h"

@interface vechileSearchViewController ()<UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UITextField *textField;
@property(nonatomic, strong)UITableView   *tableView;   // 表视图

@end

@implementation vechileSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initWithView];
}

#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.textField resignFirstResponder];
    return YES;
}

#pragma mark UITableViewDelegaet
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indentifer = @"setouAddressCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifer];
    }
    cell.textLabel.text = @"物流车辆列表";
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.textColor = [UIColor HexStrWithColor:@"8E8E8E"];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    logisticsVechileViewController *logisticsVechileVC = [[logisticsVechileViewController alloc] init];
    [self.navigationController pushViewController:logisticsVechileVC animated:YES];
}


#pragma mark 搜索按钮事件
- (void)searchButtonAction:(UIButton *)button{
    NSLog(@"开始搜索");
}

/**
 *  初始化视图
 */
- (void)initWithView{
    // 导航栏上的搜索框
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(50, 0, 200, 30)];
    self.textField.placeholder = @"请输入地址";
    self.textField.borderStyle = UITextBorderStyleRoundedRect;
    self.navigationItem.titleView = self.textField;
    self.textField.delegate = self;
    self.textField.backgroundColor = [UIColor HexStrWithColor:@"E0E0E0"];
    self.textField.userInteractionEnabled = YES;
    
    // 搜索框上的搜索按钮图片
    UIButton *searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    searchButton.frame = CGRectMake(self.textField.frame.size.width - 24, (self.textField.frame.size.height - 14) / 2, 14, 14);
    [searchButton setImage:[UIImage imageNamed:@"fdj"] forState:UIControlStateNormal];
    [self.textField addSubview:searchButton];
    [searchButton addTarget:self action:@selector(searchButtonAction:) forControlEvents:UIControlEventTouchDown];
    
    // 列表
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight - 20) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.tableHeaderView = [self headerView];
    [self.view addSubview:self.tableView];
    
}

/**
 *  列表头
 *
 *  @return 列表头
 */
- (UIView *)headerView{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, kNavHeight, kUIScreenWidth, 40)];
    
    UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth + 2, 40)];
    lineLabel.backgroundColor = [UIColor HexStrWithColor:@"FF8000"];
    lineLabel.text = @"审核状态:审核中，预计两个工作日完成";
    lineLabel.font = [UIFont systemFontOfSize:14];
    lineLabel.textColor = [UIColor whiteColor];
    lineLabel.textAlignment = 1;
    
    [view addSubview:lineLabel];
    
    return view;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
